<include file="Public/head"/>
<body class="no-skin">
<include file="Public/header"/>

<div class="main-container" id="main-container">


    <include file="Public/sidebar"/>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs"/>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set"/>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <form class="form-horizontal" id="form" method="post" action="{:U('update')}">

                            <!-- PAGE CONTENT BEGINS -->

                            <input type="hidden" name="id" value="{$res.id}" id="id"/>

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    凭证编号 </label>
                                <div class="col-sm-2">
                                    <span class="col-sm-1 grain-line-height" style="color: red">{$res.voucher_no}</span>
                                    <input type="hidden" name="voucher_no"
                                           class="col-xs-10 col-sm-4" value="{$res['voucher_no']}">
                                </div>

                                <label class="col-sm-1 control-label no-padding-right" >
                                    日期
                                </label>
                                <div class="col-sm-4">
                                    <div class="input-group col-xs-5">
                                        <eq name="res.date" value="">
                                            <span class="col-sm-12 grain-line-height" >{$date|date="Y-m-d",###}</span>
                                            <input type="hidden" name="date"
                                                   class="col-xs-10 col-sm-4" value="{$date}">
                                            <else/>
                                            <span class="col-sm-12 grain-line-height" >{$res.date|date="Y-m-d",###}</span>
                                            <input type="hidden" name="date" class="col-xs-10 col-sm-4" value="{$res['date']}">
                                        </eq>
                                    </div>
                                    <span class="help-inline col-xs-12 col-sm-7">
                                        <span class="middle"></span>
                                    </span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" >
                                    承运单位
                                </label>
                                <div class="col-sm-2">
                                    <input type="text" name="chengyundanwei" id="chengyundanwei" placeholder="承运单位" class="col-xs-10 col-sm-12" value="{$res['chengyundanwei']}">
                                </div>
                                <label class="col-sm-1 control-label no-padding-right" >
                                    司机 </label>
                                <div class="col-sm-2">
                                        <input type="text" name="driver" id="driver" placeholder="司机" class="col-xs-10 col-sm-12" value="{$res['driver']}">
                                </div>
                                <label class="col-sm-1 control-label no-padding-right" >
                                    车牌号 </label>
                                <div class="col-sm-2">
                                    <input type="text" name="car_number"  placeholder="车牌号" class="col-xs-10 col-sm-12" value="{$res['car_number']}">
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" >
                                    出库地点
                                </label>
                                <div class="col-sm-3">
                                    <input type="text" name="chukudidian" id="chukudidian" placeholder="出库地点" class="col-xs-10 col-sm-12" value="{$res['chukudidian']}">
                                </div>
                                <label class="col-sm-1 control-label no-padding-right" >
                                    收货地点 </label>
                                <div class="col-sm-3">
                                    <input type="text" name="shouhuodidian" id="shouhuodidian" placeholder="收货地点" class="col-xs-10 col-sm-12" value="{$res['shouhuodidian']}">
                                </div>

                            </div>
                            <!--<div class="space-4"></div>-->
                            <!--<div class="form-group">-->
                                <!--<label class="col-sm-1 control-label no-padding-right" >-->
                                    <!--地址 </label>-->
                                <!--<div class="col-sm-2">-->
                                    <!--<input type="text" name="address"  placeholder="请填写售粮人地址" class="col-xs-10 col-sm-12" value="{$res['card_number']}">-->
                                <!--</div>-->
                            <!--</div>-->
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" >
                                    粮食品种 </label>
                                <div class="col-sm-2">
                                        <select id="foodstuff_id" name="foodstuff_id" class="col-xs-10 col-sm-12">
                                            <option value="">--- 请选择粮食品种 ---</option>
                                            <volist name="foodstuff_array" id="vo">
                                                <eq name="res.foodstuff_id" value="$vo.id">

                                                    <option value="{$vo.id}" selected="selected">{$vo.name}</option>

                                                    <else/>

                                                    <option value="{$vo.id}">{$vo.name}</option>
                                                </eq>

                                            </volist>
                                        </select>
                                </div>
                                <label class="col-sm-1 control-label no-padding-right" >
                                    等级 </label>
                                <div class="col-sm-2">

                                    <select id="level"  name="level" class="col-xs-10 col-sm-12">
                                        <option value="">--- 请选择粮食等级 ---</option>
                                        <for start="1" end="6">
                                            <eq name="res.level" value="$i">
                                                <option value="{$i}" selected="selected">{$i}</option>
                                                <else/>
                                                <option value="{$i}">{$i}</option>
                                            </eq>
                                        </for>
                                    </select>
                                </div>
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    单价
                                </label>
                                <div class="col-sm-2">
                                    <input type="text" name="price" id="price"
                                           class="col-xs-10 col-sm-7 data" style="color: red"  value="{$res.price}">
                                    <span class="col-sm-5 grain-line-height">&nbsp;元 / kg</span>

                                </div>
                            </div>


                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right">
                                    水分 </label>
                                <div class="col-sm-1">
                                    <input type="text" name="shuifen" id="shuifen"
                                           class="col-xs-10 col-sm-8 data" value="{$res['shuifen']}">
                                    <span class="col-sm-1 grain-line-height">&nbsp;%</span>
                                </div>
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    原发件数 </label>
                                <div class="col-sm-1">
                                    <input type="text" name="yuanfajianshu" id="yuanfajianshu"
                                           class="col-xs-10 col-sm-8 data" value="{$res['yuanfajianshu']}">
                                    <span class="col-sm-1 grain-line-height">&nbsp;</span>
                                </div>
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    实收件数 </label>
                                <div class="col-sm-1">
                                    <input type="text" name="shishoujianshu" id="shishoujianshu"
                                           class="col-xs-10 col-sm-8 data" value="{$res['shishoujianshu']}">
                                    <span class="col-sm-1 grain-line-height">&nbsp;</span>
                                </div>
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    定量包装 </label>
                                <div class="col-sm-1">
                                    <input type="text" name="dingliangbaozhuang" id="dingliangbaozhuang"
                                           class="col-xs-10 col-sm-8 data" value="{$res['dingliangbaozhuang']}">
                                    <span class="col-sm-1 grain-line-height">&nbsp;</span>
                                </div>
                            </div>




                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right">毛重 </label>
                                <div class="col-sm-1">
                                    <input type="text" name="maozhong" id="maozhong"
                                           class="col-xs-10 col-sm-8 weight" value="{$res['maozhong']}">
                                    <span class="col-sm-1 grain-line-height">&nbsp;kg</span>
                                </div>
                                <label class="col-sm-1 control-label no-padding-right">皮重 </label>
                                <div class="col-sm-1">
                                    <input type="text" name="pizhong" id="pizhong"
                                           class="col-xs-10 col-sm-8 weight" value="{$res['pizhong']}">
                                    <span class="col-sm-1 grain-line-height">&nbsp;kg</span>
                                </div>
                                <label class="col-sm-1 control-label no-padding-right">袋皮重量 </label>
                                <div class="col-sm-1">
                                    <input type="text" name="daipizhongliang" id="daipizhongliang"
                                           class="col-xs-10 col-sm-8 weight" value="{$res['daipizhongliang']}">
                                    <span class="col-sm-1 grain-line-height">&nbsp;kg</span>
                                </div>
                                <label class="col-sm-1 control-label no-padding-right"> 净重 </label>
                                <div class="col-sm-1">
                                    <input type="text" name="jingzhong" id="jingzhong" style="color:red"
                                           class="col-xs-10 col-sm-8 grain-important-info weight" value="{$res['jingzhong']}">
                                    <span class="col-sm-1 grain-line-height">&nbsp;kg</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right">大写金额 </label>
                                <div class="col-sm-2">
                                    <input type="text" name="daxiejine" id="daxiejine" class="col-xs-10 col-sm-12" value="{$res['daxiejine']}">
                                </div>

                                <label class="col-sm-1 control-label no-padding-right">合计金额 </label>
                                <div class="col-sm-2">
                                        <span class="col-sm-4 grain-line-height" id="hejijine-text" style="color:red; ">
                                          <eq name="res.hejijine" value="">
                                              0.00
                                              <else/>
                                              {$res['hejijine']}
                                          </eq>
                                        </span>
                                    <input type="hidden" name="hejijine" id="hejijine"
                                           class="col-xs-10 col-sm-8 grain-important-info" value="{$res['hejijine']}">
                                    <span class="col-sm-1 grain-line-height">&nbsp;元</span>
                                </div>
                                <label class="col-sm-1 control-label no-padding-right" >实际金额 </label>
                                <div class="col-sm-2">
                                    <input type="text" name="shijijine" id="shijijine"
                                           class="col-xs-10 col-sm-4" style="color:red" value="{$res['shijijine']}">
                                    <span class="col-sm-1 grain-line-height">&nbsp;元</span>
                                </div>



                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right">备注 </label>
                                <div class="col-sm-4">
                                    <textarea name="beizhu" id="beizhu" class="col-xs-10 col-sm-8">{$res['beizhu']}</textarea>

                                    <span class="col-sm-1 grain-line-height">&nbsp;</span>
                                </div>
                            </div>

                            <div class="col-md-offset-2 col-md-9">
                                <button class="btn btn-info submit" type="button">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>
                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="reset">
                                    <i class="icon-undo bigger-110"></i>
                                    重置
                                </button>
                            </div>

                        </form>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <include file="Public/footer"/>

</div><!-- /.main-container -->

<include file="Public/footerjs"/>
<!-- inline scripts related to this page -->
<script src="__PUBLIC__/qwadmin/js/date-time/bootstrap-datepicker.js"></script>
<!--<script src="__PUBLIC__/qwadmin/js/function.js"></script>-->

<script type="text/javascript">
    function getPrice(){
        var foodstuff_id = $("#foodstuff_id").val();
        var level = $("#level").val();
        if(foodstuff_id!="" && level!=""){
            $.ajax({
                data:{foodstuff_id:foodstuff_id,level:level},
                dataType:"json",
                type:"post",
                url:"{:U('getPrice')}",
                success:function(msg){
                    if(msg.status==1){
//                        return msg.price;
                        $("#price").val(msg.price);
                    }else{
                        $("#price").val(0);
                    }
                }
            })

        }
    }

    //价款计算器
    function totalCalculator(){
        var price= isnan(parseFloat($("#price").val()));
        var jingzhong = isnan(parseFloat($("#jingzhong").val()));
        var total = 0;
        if(price!=0 && jingzhong!=0){
            total = price*jingzhong;
        }
        return total.toFixed(2);
    }

    //重量计算器
    function weightCalculator(){
        var maozhong = isnan(parseFloat($("#maozhong").val()));
        var pizhong = isnan(parseFloat($("#pizhong").val()));
        var daipizhongliang = isnan(parseFloat($("#daipizhongliang").val()));
        var jingzhong =0 ;
        if(maozhong!=0 && pizhong!=0 && daipizhongliang!=0 && maozhong>pizhong+daipizhongliang){
            jingzhong = maozhong-pizhong-daipizhongliang;
        }
        return jingzhong.toFixed(2);
    }



    function isnan(value){
        return isNaN(value) ? 0 : value;

    }



    $(function () {
        $("#foodstuff_id").change(function(){
            getPrice();
            var total = totalCalculator();
            $("#hejijine").val(total);
            $("#hejijine-text").html(total);
            $("#shijijine").val(total);

        });
        $("#level").change(function(){
            getPrice();
            var total = totalCalculator();
            $("#hejijine").val(total);
            $("#hejijine-text").html(total);
            $("#shijijine").val(total);
        });




        $(".weight").not("[name='jingzhong']").keyup(function(){
            var jingzhong = weightCalculator();
            $("#jingzhong").val(jingzhong);

            var total = totalCalculator();
            $("#hejijine").val(total);
            $("#hejijine-text").html(total);
            $("#shijijine").val(total);


        });


        $("#price").keyup(function(){
            var total = totalCalculator();
            $("#hejijine").val(total);
            $("#hejijine-text").html(total);
            $("#shijijine").val(total);

        });
        $("#jingzhong").keyup(function(){
            var total = totalCalculator();
            $("#hejijine").val(total);
            $("#hejijine-text").html(total);
            $("#shijijine").val(total);

        });

        jQuery(function ($) {
            $('[name="date"]').datepicker({
                format: 'yyyy-mm-dd',
                weekStart: 1,
                autoclose: true,
                todayBtn: 'linked',
                language: 'cn'
            });
        });

        $(".submit").click(function () {
//            var shuifen = $("#shuifen").val();
//            if (shuifen == '') {
//                bootbox.dialog({
//                    title: '友情提示：',
//                    message: "仓库名称必须填写。",
//                    buttons: {
//                        "success": {
//                            "label": "确定",
//                            "className": "btn-danger"
//                        }
//                    }
//                });
//                return;
//            }
            $("#form").submit();
        });
    });
</script>
</body>
</html>
